package com.smart.pojo;

import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
public class ResultBean {
    private Integer code;
    private Integer errno;
    private String message;
    private Object data;

    private static final ResultBean resultBean = new ResultBean();

    public static ResultBean success(Object data) {
        resultBean.code = 200;
        resultBean.message = "操作成功";
        resultBean.data = data;
        return resultBean;
    }

    public static ResultBean success(Object data, String message) {
        resultBean.code = 200;
        resultBean.message = message;
        resultBean.data = data;
        return resultBean;
    }

    public static ResultBean success() {
        resultBean.code = 200;
        resultBean.message = "操作成功";
        resultBean.data = null;
        return resultBean;
    }

    public static ResultBean error(String message) {
        resultBean.code = 500;
        resultBean.message = message;
        resultBean.data = null;
        return resultBean;
    }

    public static ResultBean error() {
        resultBean.code = 500;
        resultBean.message = "服务器异常，请稍后再试";
        resultBean.data = null;
        return resultBean;
    }

    public static ResultBean unAuthentication() {
        resultBean.code = 401;
        resultBean.message = "当前认证已过期，请先登录";
        resultBean.data = null;
        return resultBean;
    }

    public static ResultBean uploadSuccess(String url, String alt, String href) {
        resultBean.errno = 0;
        Map<String, String> map = new HashMap<>();
        map.put("url", url);
        map.put("alt", alt);
        map.put("href", href);
        resultBean.data = map;
        return resultBean;
    }

    public static ResultBean uploadError() {
        resultBean.errno = 1;
        resultBean.message = "图片上传失败";
        return resultBean;
    }

}
